package CollectionsFramework;

import java.util.Optional;
import java.util.Scanner;

public class OptionalTest {
    public static void main(String[] args) {
        Scanner scanner = new Scanner(System.in);
        User user = new User("Tom",12);
        int i = scanner.nextInt();
        if(i==0) {
             user = null;
        }
        Optional<User>optional = Optional.ofNullable(user);
//        User user1 = optional.orElse(new User("root", 0));
//        System.out.println(user1.getName());

//        optional.ifPresent(System.out::println);

//        User user1 = optional.orElseGet(User::new);
//        System.out.println(user1.getName());

        User user1 = optional.orElseThrow(() -> new RuntimeException("hahahaha"));
        System.out.println(user1.getName());


    }
}
